package chapter5.postconstruct_annotation;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class TestBean {
	private static SimpleBeanWithJSR250 getBean(String beanName,
			ApplicationContext ctx) {
		try {
			SimpleBeanWithJSR250 bean = (SimpleBeanWithJSR250) ctx
					.getBean(beanName);
			System.out.println(beanName);
			return bean;
		} catch (BeanCreationException e) {
			System.out.println("An error occured in bean configuration: "
					+ e.getMessage());
			return null;
		}
	}

	public static void main(String[] args) {
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:chapter5/postconstruct_annotation/initInterface.xml");
		ctx.refresh();

		SimpleBeanWithJSR250 bean1 = getBean("bean1", ctx);
		System.out.println(bean1.toString());
		SimpleBeanWithJSR250 bean2 = getBean("bean2", ctx);
		System.out.println(bean2.toString());
		SimpleBeanWithJSR250 bean3 = getBean("bean3", ctx);
		System.out.println(bean3.toString());
	}
}
